# -*- coding: utf-8 -*-
import scrapy
from tutorial.items import TutorialItem


class MoviepiaofangspiderSpider(scrapy.Spider):
    name = 'moviePiaofangSpider'
    allowed_domains = ['eastmoney.com']
    start_urls = ['http://fund.eastmoney.com/fund.html']

    def parse(self, response):
        #嵌套选择器
        subSelector=response.xpath('//div[@id="tableDiv"]/table/tbody/tr')

        dateSelector=response.xpath('//div[@id="tableDiv"]/table/thead/tr/td[@colspan="2"][1]/span/text()')

        dtDate=dateSelector
        items=[]

        for sub in subSelector:
            item=TutorialItem()
            item['stock_code']=sub.xpath('./td[@class="bzdm"]/text()').extract()[0]
            item['stock_name']=sub.xpath('./td[@class="tol"]/nobr/a[@title]/text()').extract()[0]
            item['stock_dwjz']=sub.xpath('./td[@class="dwjz black"][1]/text()').extract()[0]
            item['stock_date']=dtDate.extract()[0]

            items.append(item)

        return items

